package elcs.test.model;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Repository;

import elcs.member.model.MemberDao;
import elcs.member.model.MemberVO;
import elcs.point.model.TradePointDao;
import elcs.point.model.TradePointVO;
@Repository
public class QuestionServiceImpl implements QuestionService{
	@Resource(name="questionDaoImpl")
	private QuestionDao questionDao;
	@Resource(name="memberDaoImpl")
	private MemberDao memberDao;
	@Resource(name="testDaoImpl")
	private TestDao testDao;
	@Resource(name="tradePointDaoImpl")
	private TradePointDao tradePointDao;
	@Override
	public List joinTest() {
		// TODO Auto-generated method stub
		List list=questionDao.joinQuestionByRandom();
	
		return list;
		
	}

	@Override
	public int jointestResult(HttpSession session, String total) {
		int resultTotal = Integer.parseInt(total);
		MemberVO mvo=(MemberVO)session.getAttribute("mvo");
		System.out.println(mvo);
		if(resultTotal<3)
		{
			mvo.setLevel(1);
		}
		else if(resultTotal<5)
		{
			mvo.setLevel(2);
		}
		else if(resultTotal<7)
		{
			mvo.setLevel(3);
		}
		else 
		{
			mvo.setLevel(4);
		}
		System.out.println(mvo);
		memberDao.updateMemberByLevel(mvo);
		
		/*testDao.registerTest();*/
		session.setAttribute("mvo", mvo);
		return mvo.getLevel();
		
		
	}

	@Override
	public List levelUpTest(int i,HttpSession session) {
		// TODO Auto-generated method stub
		System.out.println(i+"level test ");
		List list=questionDao.levelQuestionByRandom(i);
		MemberVO mvo=(MemberVO)session.getAttribute("mvo");
		
		
		return list;
	}

	@Override
	public boolean leveltestResult(HttpSession session, String total) {
		// TODO Auto-generated method stub
		int resultTotal = Integer.parseInt(total);
		MemberVO mvo=(MemberVO)session.getAttribute("mvo");
		System.out.println(mvo);
		
		if(resultTotal>=7)
		{
			System.out.println(mvo);
			mvo.setLevel(mvo.getLevel()+1);
			memberDao.updateMemberByLevel(mvo);
			System.out.println(mvo);
			session.setAttribute("mvo", mvo);
			return true;
		}
	
		
	
		
		return false;
		
	}
	
}
